#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	int x,y;
	for(int i = 1;i<=5;i++)
	for(int j = 1;j<=5;j++)
	{
		int a;
		scanf("%d",&a);
		if(a==1)
		{
			x = i;
			y = j;
		}
	}
	printf("%d\n",abs(x-3)+abs(y-3));
}
